package config

//package main

import (
	"fmt"
	"io/ioutil"

	"gopkg.in/yaml.v2"
)

/*
const (
	PlaybookTaskQueue = "playbook_tasks_queue"
	VerificationPass  = "7201a06436fd56"
)
*/

type Conf struct {
	Mysql mysql `yaml:"mysql_config"`
	Redis redis `yaml:"redis_config"`
	//	HttpAuth HttpAuth `yaml:"http_auth_config"`
}

//profile variables
type mysql struct {
	Host   string `yaml:"host"`
	User   string `yaml:"user"`
	Pwd    string `yaml:"pwd"`
	Dbname string `yaml:"dbname"`
}

type redis struct {
	Host string `yaml:"host"`
	Port int    `yaml:"port"`
	Pwd  string `yaml:"pwd"`
	Db   int    `yaml:"db"`
}

/*
var HttpAuthPass map[string]string

type HttpAuth struct {
	k HttpAuthPass
}
*/
//func (c *Conf) GetConf(path string) *Conf {
func (c *Conf) GetConf(path string) *Conf {

	//func (c *Conf) GetConf() {
	//HttpAuthPass = make(map[string]string)

	//yamlFile, err := ioutil.ReadFile("F:\\gocode\\src\\ansible-api-go\\config\\conf.yaml")

	yamlFile, err := ioutil.ReadFile(path)
	if err != nil {
		fmt.Println("Error:read config conf.yaml error")
		fmt.Println(err.Error())
	}
	err = yaml.Unmarshal(yamlFile, c)
	if err != nil {
		fmt.Println(err.Error())
	}
	return c
}

var SelfConf Conf

/*
func init() {
	var c Conf
	SelfConf = c.GetConf()
	fmt.Println(SelfConf.Redis.Host)
	//fmt.Println(conf.mysql_config.Pwd)
}
*/
